package com.os.opencv.java.chapter4;

import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.highgui.HighGui;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;

public class Pyrmaids {

    public static void main(String[] args) {
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

        //读取图像文件并在屏幕上显示
        Mat src = Imgcodecs.imread("/Users/matt/MATT-MAC/matt_workspace/OS-OpenCV_workspace/view.jpg");
        HighGui.imshow("src", src);
        HighGui.waitKey(0);

        //对图像进行向下采样并在屏幕上显示
        Mat dst = new Mat();
        Imgproc.pyrDown(src, dst);
        HighGui.imshow("down", dst);
        HighGui.waitKey(0);

        //对向下采样后的图像进行向上采样并在屏幕上显示
        Imgproc.pyrUp(dst, dst);
        HighGui.imshow("up", dst);
        HighGui.waitKey(0);

        //将两次采样后的图像与原图相减
        Mat mat = new Mat(src.size(), CvType.CV_64F);
        Core.subtract(dst, src, mat);

        //进行反相操作并在屏幕上显示
        Core.bitwise_not(mat, mat);
        HighGui.imshow("diff", mat);
        HighGui.waitKey(0);

        System.exit(0);
    }
}
